﻿Public Class EventLogExt

    Public Property Source As String
    Public Property Log As String

    Public Sub New(ByVal source As String, ByVal log As String)
        Me.Source = source
        Me.Log = log
        CreateEventLog()
    End Sub

    Public Function CreateEventLog() As Boolean
        Dim exist As Boolean
        Try
            If Not String.IsNullOrWhiteSpace(Source) AndAlso Not String.IsNullOrWhiteSpace(Log) Then
                If Not EventLog.SourceExists(Source) Then
                    EventLog.CreateEventSource(Source, Log)
                End If
                exist = True
            Else
                exist = False
            End If
        Catch ex As Exception
            Throw ex
        End Try
        Return exist
    End Function

    Public Sub WriteToLog(ByVal message As String, ByVal type As System.Diagnostics.EventLogEntryType)
        EventLog.WriteEntry(Source, message, type)
    End Sub

    Public Sub WriteToLog(ByVal message As String, ByVal type As System.Diagnostics.EventLogEntryType, ByVal eventID As Integer)
        EventLog.WriteEntry(Source, message, type, eventID)
    End Sub

    Public Sub WriteToLog(ByVal message As String, ByVal type As System.Diagnostics.EventLogEntryType, ByVal eventID As Integer, ByVal category As Short)
        EventLog.WriteEntry(Source, message, type, eventID, category)
    End Sub

End Class
